<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品型号" prop="productModel">
        <el-input
          v-model="queryParams.productModel"
          placeholder="请输入产品型号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编码" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品图例" prop="productLegend">
        <el-input
          v-model="queryParams.productLegend"
          placeholder="请输入产品图例"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品数量" prop="productQuantity">
        <el-input
          v-model="queryParams.productQuantity"
          placeholder="请输入产品数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="零件名称" prop="partName">
        <el-input
          v-model="queryParams.partName"
          placeholder="请输入零件名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="适用机型" prop="applicableModel">
        <el-input
          v-model="queryParams.applicableModel"
          placeholder="请输入适用机型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="零件图号" prop="drawingNum">
        <el-input
          v-model="queryParams.drawingNum"
          placeholder="请输入零件图号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="零件编码" prop="partNumber">
        <el-input
          v-model="queryParams.partNumber"
          placeholder="请输入零件编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订货数量" prop="orderQuantity">
        <el-input
          v-model="queryParams.orderQuantity"
          placeholder="请输入订货数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计量单位" prop="measurementUnit">
        <el-input
          v-model="queryParams.measurementUnit"
          placeholder="请输入计量单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区分状态" prop="differentiateStates">
        <el-input
          v-model="queryParams.differentiateStates"
          placeholder="请输入区分状态"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发生时间" prop="occurrence">
        <el-date-picker clearable
          v-model="queryParams.occurrence"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发生时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="涉及装备" prop="involvedEquipment">
        <el-input
          v-model="queryParams.involvedEquipment"
          placeholder="请输入涉及装备"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涉及承制单位" prop="unitsInvolved">
        <el-input
          v-model="queryParams.unitsInvolved"
          placeholder="请输入涉及承制单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="军代表室" prop="representativeOffice">
        <el-input
          v-model="queryParams.representativeOffice"
          placeholder="请输入军代表室"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="问题类别" prop="problemCategory">
        <el-input
          v-model="queryParams.problemCategory"
          placeholder="请输入问题类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="负责人" prop="head">
        <el-input
          v-model="queryParams.head"
          placeholder="请输入负责人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原因分析" prop="causeAnalysis">
        <el-input
          v-model="queryParams.causeAnalysis"
          placeholder="请输入原因分析"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="解决进展" prop="resolutionProgress">
        <el-input
          v-model="queryParams.resolutionProgress"
          placeholder="请输入解决进展"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="问题整改计划时限" prop="problemRectification">
        <el-input
          v-model="queryParams.problemRectification"
          placeholder="请输入问题整改计划时限"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建者" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="updateBy">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        <el-date-picker clearable
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择更新时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:issues:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:issues:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:issues:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:issues:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="issuesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="产品名称" align="center" prop="productName" />
      <el-table-column label="产品类型" align="center" prop="productType" />
      <el-table-column label="产品型号" align="center" prop="productModel" />
      <el-table-column label="产品编码" align="center" prop="productCode" />
      <el-table-column label="产品图例" align="center" prop="productLegend" />
      <el-table-column label="产品数量" align="center" prop="productQuantity" />
      <el-table-column label="零件名称" align="center" prop="partName" />
      <el-table-column label="零件类型" align="center" prop="partType" />
      <el-table-column label="适用机型" align="center" prop="applicableModel" />
      <el-table-column label="零件图号" align="center" prop="drawingNum" />
      <el-table-column label="零件编码" align="center" prop="partNumber" />
      <el-table-column label="订货数量" align="center" prop="orderQuantity" />
      <el-table-column label="计量单位" align="center" prop="measurementUnit" />
      <el-table-column label="区分状态" align="center" prop="differentiateStates" />
      <el-table-column label="发生时间" align="center" prop="occurrence" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.occurrence, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="涉及装备" align="center" prop="involvedEquipment" />
      <el-table-column label="简要情况" align="center" prop="briefSituation" />
      <el-table-column label="涉及承制单位" align="center" prop="unitsInvolved" />
      <el-table-column label="军代表室" align="center" prop="representativeOffice" />
      <el-table-column label="问题类别" align="center" prop="problemCategory" />
      <el-table-column label="负责人" align="center" prop="head" />
      <el-table-column label="原因分析" align="center" prop="causeAnalysis" />
      <el-table-column label="解决进展" align="center" prop="resolutionProgress" />
      <el-table-column label="问题整改计划时限" align="center" prop="problemRectification" />
      <el-table-column label="质量问题类型" align="center" prop="qualityIssuesType" />
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="部门ID" align="center" prop="deptId" />
      <el-table-column label="创建者" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="updateBy" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="备注1" align="center" prop="note1" />
      <el-table-column label="备注2" align="center" prop="note2" />
      <el-table-column label="备注3" align="center" prop="note3" />
      <el-table-column label="备注4" align="center" prop="note4" />
      <el-table-column label="备注5" align="center" prop="note5" />
      <el-table-column label="备注6" align="center" prop="note6" />
      <el-table-column label="备注7" align="center" prop="note7" />
      <el-table-column label="备注8" align="center" prop="note8" />
      <el-table-column label="备注9" align="center" prop="note9" />
      <el-table-column label="备注10" align="center" prop="note10" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:issues:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:issues:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改质量问题对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="产品名称" prop="productName">
          <el-input v-model="form.productName" placeholder="请输入产品名称" />
        </el-form-item>
        <el-form-item label="产品型号" prop="productModel">
          <el-input v-model="form.productModel" placeholder="请输入产品型号" />
        </el-form-item>
        <el-form-item label="产品编码" prop="productCode">
          <el-input v-model="form.productCode" placeholder="请输入产品编码" />
        </el-form-item>
        <el-form-item label="产品图例" prop="productLegend">
          <el-input v-model="form.productLegend" placeholder="请输入产品图例" />
        </el-form-item>
        <el-form-item label="产品数量" prop="productQuantity">
          <el-input v-model="form.productQuantity" placeholder="请输入产品数量" />
        </el-form-item>
        <el-form-item label="零件名称" prop="partName">
          <el-input v-model="form.partName" placeholder="请输入零件名称" />
        </el-form-item>
        <el-form-item label="适用机型" prop="applicableModel">
          <el-input v-model="form.applicableModel" placeholder="请输入适用机型" />
        </el-form-item>
        <el-form-item label="零件图号" prop="drawingNum">
          <el-input v-model="form.drawingNum" placeholder="请输入零件图号" />
        </el-form-item>
        <el-form-item label="零件编码" prop="partNumber">
          <el-input v-model="form.partNumber" placeholder="请输入零件编码" />
        </el-form-item>
        <el-form-item label="订货数量" prop="orderQuantity">
          <el-input v-model="form.orderQuantity" placeholder="请输入订货数量" />
        </el-form-item>
        <el-form-item label="计量单位" prop="measurementUnit">
          <el-input v-model="form.measurementUnit" placeholder="请输入计量单位" />
        </el-form-item>
        <el-form-item label="区分状态" prop="differentiateStates">
          <el-input v-model="form.differentiateStates" placeholder="请输入区分状态" />
        </el-form-item>
        <el-form-item label="发生时间" prop="occurrence">
          <el-date-picker clearable
            v-model="form.occurrence"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发生时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="涉及装备" prop="involvedEquipment">
          <el-input v-model="form.involvedEquipment" placeholder="请输入涉及装备" />
        </el-form-item>
        <el-form-item label="简要情况" prop="briefSituation">
          <el-input v-model="form.briefSituation" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="涉及承制单位" prop="unitsInvolved">
          <el-input v-model="form.unitsInvolved" placeholder="请输入涉及承制单位" />
        </el-form-item>
        <el-form-item label="军代表室" prop="representativeOffice">
          <el-input v-model="form.representativeOffice" placeholder="请输入军代表室" />
        </el-form-item>
        <el-form-item label="问题类别" prop="problemCategory">
          <el-input v-model="form.problemCategory" placeholder="请输入问题类别" />
        </el-form-item>
        <el-form-item label="负责人" prop="head">
          <el-input v-model="form.head" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="原因分析" prop="causeAnalysis">
          <el-input v-model="form.causeAnalysis" placeholder="请输入原因分析" />
        </el-form-item>
        <el-form-item label="解决进展" prop="resolutionProgress">
          <el-input v-model="form.resolutionProgress" placeholder="请输入解决进展" />
        </el-form-item>
        <el-form-item label="问题整改计划时限" prop="problemRectification">
          <el-input v-model="form.problemRectification" placeholder="请输入问题整改计划时限" />
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注1" prop="note1">
          <el-input v-model="form.note1" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注2" prop="note2">
          <el-input v-model="form.note2" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注3" prop="note3">
          <el-input v-model="form.note3" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注4" prop="note4">
          <el-input v-model="form.note4" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注5" prop="note5">
          <el-input v-model="form.note5" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注6" prop="note6">
          <el-input v-model="form.note6" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注7" prop="note7">
          <el-input v-model="form.note7" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注8" prop="note8">
          <el-input v-model="form.note8" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注9" prop="note9">
          <el-input v-model="form.note9" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注10" prop="note10">
          <el-input v-model="form.note10" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listIssues, getIssues, delIssues, addIssues, updateIssues } from "@/api/system/issues";

export default {
  name: "Issues",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 质量问题表格数据
      issuesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        productName: null,
        productType: null,
        productModel: null,
        productCode: null,
        productLegend: null,
        productQuantity: null,
        partName: null,
        partType: null,
        applicableModel: null,
        drawingNum: null,
        partNumber: null,
        orderQuantity: null,
        measurementUnit: null,
        differentiateStates: null,
        occurrence: null,
        involvedEquipment: null,
        briefSituation: null,
        unitsInvolved: null,
        representativeOffice: null,
        problemCategory: null,
        head: null,
        causeAnalysis: null,
        resolutionProgress: null,
        problemRectification: null,
        qualityIssuesType: null,
        userId: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        measurementUnit: [
          { required: true, message: "计量单位不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询质量问题列表 */
    getList() {
      this.loading = true;
      listIssues(this.queryParams).then(response => {
        this.issuesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        productName: null,
        productType: null,
        productModel: null,
        productCode: null,
        productLegend: null,
        productQuantity: null,
        partName: null,
        partType: null,
        applicableModel: null,
        drawingNum: null,
        partNumber: null,
        orderQuantity: null,
        measurementUnit: null,
        differentiateStates: null,
        occurrence: null,
        involvedEquipment: null,
        briefSituation: null,
        unitsInvolved: null,
        representativeOffice: null,
        problemCategory: null,
        head: null,
        causeAnalysis: null,
        resolutionProgress: null,
        problemRectification: null,
        qualityIssuesType: null,
        userId: null,
        deptId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加质量问题";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getIssues(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改质量问题";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateIssues(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addIssues(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除质量问题编号为"' + ids + '"的数据项？').then(function() {
        return delIssues(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/issues/export', {
        ...this.queryParams
      }, `issues_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
